# -*- coding: utf-8 -*-
"""
Created on Fri Mar 20 13:27:47 2020

@author: Administrator
"""

import requests
import sys
import io

#sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') #改变标准输出的默认编码

#登录时需要POST的数据
data = {"language": "zh_cn",
        "supplierLoginType": "SAP",
        "elsAccount": "110829",
        "elsSubAccount": "1001",
        "elsSubAccountPassword": "74074de07b6519753a21c8234e190e34",
        "identifyCode": "8118",
        "loginType": "",
        "clientType": "pc",
        "clientOs": "Win7",
        "browser": "chrome/80.0.3987.149"}

#设置请求头
headers = {'User-agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'}

#登录时表单提交到的地址（用开发者工具可以看到）
login_url = 'http://srm.nepstar.cn/ELSServer_HWXC/rest/AccountService/login'

#构造Session
session = requests.Session()

#在session中发送登录请求，此后这个session里就存储了cookie
#可以用print(session.cookies.get_dict())查看

resp = session.post(login_url, data)
print(session.cookies.get_dict())

#登录后才能访问的网页
url = 'http://srm.nepstar.cn/ELSServer_HWXC/default2.jsp?account=110829_1001&loginChage=N&telphone1=18279409642'

#发送访问请求
resp = session.get(url)

print(resp.content.decode('utf-8'))